package com.example.spring6iocxml.demoBean;

import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * @ClassName StudenTest
 * @Date 2024/5/20 20:28
 * @Description TODO
 * @User lihuajie
 * @Version 1.0.0
 **/
public class StudenTest {

    @Test
    public void test1() throws SQLException {
        ApplicationContext ac = new ClassPathXmlApplicationContext("springs.xml");
        Student student = (Student) ac.getBean("Student");
        DataSource dataSource = (DataSource) ac.getBean("druidDataSource");
        Connection connection;
        connection = dataSource.getConnection();
        System.out.println(connection);
        System.out.println(student);
    }

    @Test
    public void testLife(){
        ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("springs.xml");
        User bean =(User)ac.getBean("userone");
        System.out.println("生命周期：4、通过IOC容器获取bean并使用");
        ac.close();
    }

}
